{include file="admin/common/header" /}
<body class="pear-container">
{if($is_tips)}
<blockquote class="layui-elem-quote" style="border-left-color:#f00;background: rgba(240,0,94,0.1)">
    <p>请先开启服务在使用：</p>
    <p>config/plugin/xianrenqh/task/app.php文件中，enable值改为 true。 改好后需要命令行重启服务。</p>
</blockquote>
{/if}
<div class="layui-card">
    <div class="layui-card-body">
        <div class="layui-row hui-form-search">
            <form class="layui-form layui-col-md12" action="javascript:;" id="form_admin_search">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <input type="text" name="title" id="title" placeholder="请输入任务标题" autocomplete="off"
                               class="layui-input">
                    </div>
                    <div class="layui-inline" style="width:120px;">
                        <select name="status" id="isuse">
                            <option value="">==是否启用==</option>
                            <option value="1">已启用</option>
                            <option value="0">已禁用</option>
                        </select>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-md" data-type="reload" lay-submit="" lay-filter="search">
                            <i class="layui-icon layui-icon-search"></i>搜索
                        </button>
                        <button class="layui-btn layui-btn-danger layui-btn-md reset" type="reset">
                            <i class="layui-icon">&#xe63f;</i>清空
                        </button>
                    </div>

                </div>
            </form>
        </div>
    </div>
</div>
<div class="layui-card">
    <div class="layui-card-body">
        <table id="admin_table" lay-filter="admin_table"></table>
    </div>
</div>
<script type="text/html" id="add_toolbar">
    <button class="pear-btn pear-btn-primary pear-btn-md {php}if(!check_auth('/app/crontab/crontab/add')){ echo 'layui-hide';} {/php}"
            data-open="/app/crontab/crontab/add"
            data-title="添加任务" data-reload="2">
        <i class="layui-icon layui-icon-add-1"></i>
        新增
    </button>
</script>

<script type="text/html" id="statusTpl">
    <input type="checkbox" name="enable" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用"
           lay-filter="switchStatus"
           data-href="/app/crontab/crontab/status?id={{d.id}}" {{d.status== 1 ? 'checked' : '' }} />
</script>
<script type="text/html" id="chongzhiTpl">
    <button class="pear-btn pear-btn-primary pear-btn-sm" title="编辑" onclick="chongzhi('{{d.id}}')">
        <i class="layui-icon layui-icon-rmb"></i>
    </button>
</script>

<script type="text/html" id="barDemo">
    <button class="pear-btn pear-btn-primary pear-btn-sm" title="编辑"
            data-open="/app/crontab/crontab/edit?id={{d.id}}"
            data-title="编辑">
        <i class="layui-icon layui-icon-edit"></i>
    </button>
    <button class="pear-btn pear-btn-warming pear-btn-sm" title="重启"
            data-delete="/app/crontab/crontab/reload?id={{d.id}}"
            data-title="确定要重启此任务吗">
        <i class="layui-inline layui-icon layui-icon-refresh-3"></i>
    </button>
    <button class="pear-btn pear-btn-primary pear-btn-sm" title="日志"
            data-open="/app/crontab/crontab/logList?id={{d.id}}"
            data-title="日志">
        <i class="layui-inline layui-icon layui-icon-log"></i>
    </button>
    <button class="pear-btn pear-btn-danger pear-btn-sm" title="删除"
            data-delete="/app/crontab/crontab/delete?id={{d.id}}"
            data-title="您确定要删除吗？" data-reload="2">
        <i class="layui-icon layui-icon-delete"></i>
    </button>
</script>

{include file="admin/common/footer" /}
<script>
  layui.use(['table', 'jquery'], function () {
    var $ = layui.jquery;
    var table = layui.table;

    table.render({
      elem: '#admin_table'
      , toolbar: '#add_toolbar'
      , defaultToolbar: [{
        layEvent: 'refresh',
        icon: 'layui-icon-refresh',
        title: '刷新'
      }, 'filter']
      , method: 'get'
      , url: "/app/crontab/crontab/index"
      , cellMinWidth: 100
      , cols: [[
        {field: 'id', title: 'ID', width: 60, align: 'center'}
        , {field: 'title', title: '任务标题'}
        , {field: 'type', title: '任务类型', width: 90, align: 'center'}
        , {field: 'rule', title: '任务频率', align: 'center', width: 110}
        , {field: 'remark', title: '任务备注'}
        , {field: 'last_running_time', title: '上次执行时间', width: 160, align: 'center'}
        , {field: 'running_times', title: '执行次数', align: 'center', width: 90}
        , {field: 'sort', title: '排序', align: 'center', width: 70}
        , {field: 'create_time', title: '创建时间', width: 160, align: 'center'}
        , {field: 'status', title: '状态', templet: '#statusTpl', align: 'center', width: 100}
        , {fixed: 'right', title: '操作', toolbar: '#barDemo', align: 'center', minWidth: 200}
      ]]
      , id: 'testReload'
      , page: true
      , limit: 10
    });
    var $ = layui.$, active = {
      reload: function () {
        //执行重载
        table.reload('testReload', {
          page: {curr: 1},
          where: {
            key: {
              title: $('#title').val(),
              status: $('#isuse').val(),
            }
          }
        });
      }
    };


    $('.hui-form-search .layui-btn').on('click', function () {
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
    $('.hui-form-search .reset').on('click', function () {
      window.location.reload();
    });

    //监听行工具事件
    table.on('toolbar(admin_table)', function (obj) {
      if (obj.event === 'refresh') {
        table.reload('testReload');
      }
    });

  });
</script>
</body>
</html>
